<?php

namespace App\Model;

use App\Comment\Comment;
use Illuminate\Database\Eloquent\Model;

class BizMember extends Model
{
    protected $table = 'biz_member';

    /**
     * 商户的登录功能
     * @param $name
     * @param $pwd
     * @return bool
     */
    public function login($name, $pwd)
    {
        $info = $this -> getBizInfo(['username' => $name]);
        if (!$info){
            return false;
        }else{
            if (Comment::member_md5($pwd, config('params.password_key')) === $info['password']){
                session(['biz' => ['id' => $info['id'], 'name' => $name]]);
                return true;
            }else{
                return false;
            }
        }
    }

    /**
     * 通过条件获取商户的信息
     * @param $where
     * @return mixed
     */
    public function getBizInfo($where)
    {
        return BizMember::where($where) -> first()->toArray();
    }
}
